Socket
Socket
Sign inDemoInstall

prosemirror-inputrules

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-inputrules

Automatic transforms on text input for ProseMirror


Version published
Weekly downloads
1.1M
decreased by-21.29%
Maintainers
1
Weekly downloads
 
Created

What is prosemirror-inputrules?

The prosemirror-inputrules package provides a way to define input rules for ProseMirror editors. These rules can automatically transform text as the user types, such as converting markdown-like syntax into rich text formatting.

What are prosemirror-inputrules's main functionalities?

Basic Input Rule

This code demonstrates how to create a basic input rule that transforms a markdown-like bullet list syntax into a bullet list node in a ProseMirror editor.

const { inputRules, wrappingInputRule } = require('prosemirror-inputrules');
const { Schema } = require('prosemirror-model');
const { EditorState } = require('prosemirror-state');
const { EditorView } = require('prosemirror-view');

// Define a schema
const schema = new Schema({
  nodes: {
    doc: { content: 'block+' },
    paragraph: { content: 'inline*', group: 'block' },
    text: { group: 'inline' }
  },
  marks: {}
});

// Define an input rule
const bulletListRule = wrappingInputRule(/^\s*([-+*])\s$/, schema.nodes.bullet_list);

// Create an editor state with the input rule plugin
const state = EditorState.create({
  schema,
  plugins: [inputRules({ rules: [bulletListRule] })]
});

// Create an editor view
const view = new EditorView(document.querySelector('#editor'), {
  state
});

Custom Input Rule

This code demonstrates how to create a custom input rule that transforms a markdown-like heading syntax into a heading node in a ProseMirror editor.

const { inputRules, textblockTypeInputRule } = require('prosemirror-inputrules');
const { Schema } = require('prosemirror-model');
const { EditorState } = require('prosemirror-state');
const { EditorView } = require('prosemirror-view');

// Define a schema
const schema = new Schema({
  nodes: {
    doc: { content: 'block+' },
    heading: { content: 'inline*', group: 'block', attrs: { level: { default: 1 } } },
    text: { group: 'inline' }
  },
  marks: {}
});

// Define a custom input rule
const headingRule = textblockTypeInputRule(/^#\s$/, schema.nodes.heading, { level: 1 });

// Create an editor state with the input rule plugin
const state = EditorState.create({
  schema,
  plugins: [inputRules({ rules: [headingRule] })]
});

// Create an editor view
const view = new EditorView(document.querySelector('#editor'), {
  state
});

Other packages similar to prosemirror-inputrules

FAQs

Package last updated on 30 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc